//500.键盘行
//https://leetcode.cn/problems/keyboard-row/
class Solution {
public:
    vector<string> findWords(vector<string>& words) {
        unordered_set<char> line1;
        for (char c : "qwertyuiop") line1.insert(c);
        unordered_set<char> line2;
        for (char c : "asdfghjkl") line2.insert(c);
        unordered_set<char> line3;
        for (char c : "zxcvbnm") line3.insert(c);

        unordered_set<char>* line = nullptr;
        vector<string> ret;
        ret.reserve(words.size() / 2);
        for (string& s : words)
        {
            //词库匹配
            if (s.size() <= 0) continue;
            else if (line1.count(s[0]) || line1.count(s[0] + 32)) line = &line1;
            else if (line2.count(s[0]) || line2.count(s[0] + 32)) line = &line2;
            else if (line3.count(s[0]) || line3.count(s[0] + 32)) line = &line3;

            bool flag = true;
            //开始验证
            for (char c : s)
            {
                if (line->count(c) == 0 && line->count(c + 32) == 0)
                {
                    flag = false;
                    break;
                }
            }
            if (flag) ret.emplace_back(s);
        }
        return ret;
    }
};